<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="__CSS__/lib/normalize.css" />
    <link rel="stylesheet" type="text/css" href="__CSS__/mui-3.6.1.min.css" />
    <link rel="stylesheet" type="text/css" href="__CSS__/my_addr.css" />
    <title>收货地址</title>
</head>

<body>
    <div class="top-bar">
        <a href="{$ref}">
            <div class="return" ></div>
        </a>
        <div class="top-middle">收货地址</div>
        <div class="top-right"></div>
    </div>

    <div id="address_list">
        <ul id="address">
            <foreach name="addr" item="ad" key="k">
            <?php if($ad['isCan'] == 1){ ?>
                <li id="li{$ad.addressId}">
                    <div class="top mui-clearfix" onclick='selectAddress("{$ad.addressId}")'>
                        <div class="gps"></div>
                        <div class="name">
                            <span class="user_name">收货人：{$ad.userName}</span>
                            <span class="phone">{$ad.userPhone}</span>
                        </div>
                        <div class="dizhi">收货地址：{$ad.province}{$ad.city}{$ad.area}{$ad.community}{$ad.address}</div>
                    </div>
                    <div class="bottom">

                        <div class="s1">
                            <input id="radio{$k}" type="radio" <if condition="$ad['isDefault']">checked</if> name="default_address" onclick="setDefault({$ad.addressId})" />
                            <label for="radio{$k}" class="tu"></label>
                            <span class="title">设为默认</span>
                        </div>

                        <div onclick="delAds({$ad.addressId})" class="s3">
                            <div class="tu"></div><span class="title" >删除</span>
                        </div>

                        <a href="/Wx/Address/editAddr?id={$ad['addressId']}&r=myAddr&ref={$ref}">
                        <div class="s2" onclick="location.href='/Wx/Address/editAddr?id={$ad['addressId']}&r=myAddr&ref={$ref}'" >
                            <div class="tu"></div><span class="title">编辑</span>
                        </div>
                        </a>
                    </div>
                </li>
            <?php } ?>
            </foreach>
        </ul>
        <?php if($isRef == 1){ ?>
            <div style="text-align: center;font-size: 1em;margin: 20px 0;">以下地址超出配送范围</div>
        <?php } ?>
        <ul id="address2">
            <foreach name="addr" item="ad" key="k">
            <?php if($ad['isCan'] == 0){ ?>
                <li id="li{$ad.addressId}">
                    <div class="top mui-clearfix" onclick='shownot()'>
                        <div class="gps"></div>
                        <div class="name">
                            <span class="user_name">收货人：{$ad.userName}</span>
                            <span class="phone">{$ad.userPhone}</span>
                        </div>
                        <div class="dizhi">收货地址：{$ad.province}{$ad.city}{$ad.area}{$ad.community}{$ad.address}</div>
                    </div>
                    <div class="bottom">

                        <div class="s1">
                            <input id="radio{$k}" type="radio" <if condition="$ad['isDefault']">checked</if> name="default_address" onclick="setDefault({$ad.addressId})" />
                            <label for="radio{$k}" class="tu"></label>
                            <span class="title">设为默认</span>
                        </div>

                        <div onclick="delAds({$ad.addressId})" class="s3">
                            <div class="tu"></div><span class="title" >删除</span>
                        </div>

                        <a href="/Wx/Address/editAddr?id={$ad['addressId']}&r=myAddr&ref={$ref}">
                        <div class="s2" onclick="location.href='/Wx/Address/editAddr?id={$ad['addressId']}&r=myAddr&ref={$ref}'" >
                            <div class="tu"></div><span class="title">编辑</span>
                        </div>
                        </a>
                    </div>
                </li>
            <?php } ?>
            </foreach>
        </ul>
    </div>

    <div class="no-addr" style="<if condition="$addr" >display:none;<else />display:block;</if>">
    <div class="no-addr-img" style="background-image: url(__IMG__/no_addr.png);">
    </div>
    <div class="go-add">
        没有收货地址，快去添加一个地址吧！</div>
    </div>
    <div class="ub lh35 submit <if condition="count($addr) lt 4"><else/>wtf</if>" >
       <a href="/Wx/Address/addAddr?r=myAddr&ref={$ref}" class="add" >
            <div class="bottom-warp">
                <span class="title add-ads "></span>
                <span class="title ">新建地址</span>
            </div>
        </a>
    </div>
<script type="text/javascript" src="__JS__/mui-3.6.1.min.js"></script>
<script type="text/javascript">

function setDefault(id){
    mui.post('/Wx/Address/setDefaultAddr',{
        addrid:id
    },function(data){
        if(data.status==-3){
            mui.toast('请先登录');
            return;
        }
        if(data.status==-1){
            mui.toast('设置失败');
            return;
        }
        mui.toast('设置成功');
    },'json');
}

function delAds(id){
    mui.confirm(
        '<div class="confirm">确定要删除该地址吗？</div>',
        '提示',
        ['取消','删除'],
        function(el){
            console.log(el['index']);
            if(el['index']==1){
                delAdsPost(id);
            }
        }
    )
}

function delAdsPost(id){
    mui.post('/Wx/Address/delAddr',{
        addrid:id
    },function(data){
        if(data.status==-3){
            mui.toast('请先登录');
            return;
        }
        if(data.status==-1){
            mui.toast('删除失败');
            return;
        }
        mui.toast('删除成功');
        var el = document.getElementById('li'+id);
        el.parentNode.removeChild(el);
    },'json');
}
//确认订单选择地址
function selectAddress($addressId){
    //确认订单跳转过来 才起作用
    if ({$isRef}) {
        // alert($addressId);
        window.location.href = "{$ref}"+'/addressId/'+$addressId;
        // window.location.href='/Wx/Shop/complaint/shopId/'+shopId+'/orderId/'+orderId+'/name/'+name;
    }
}

function shownot() {
    mui.toast('该地址不在配送范围内');
}

</script>

</body>

</html>
